package com.example.gamestore.controller;

import com.example.gamestore.pojo.ShoppingCart;
import com.example.gamestore.pojo.User;
import com.example.gamestore.service.ShoppingCartService;
import com.example.gamestore.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @Autowired
    private UserService userService;

    @PostMapping("/shoppingcart/add")
    public String addToCart(@RequestBody ShoppingCart shoppingCart) {
        int result = shoppingCartService.add(shoppingCart);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }

    @GetMapping("/getByUserId/{userId}")
    public List<ShoppingCart> getByUserId(@PathVariable Long userId) {
        return shoppingCartService.getByUserId(userId);
    }


}